#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
collections是Python内建的一个集合模块，提供了许多有用的集合类。
"""
from collections import deque,namedtuple,defaultdict,OrderedDict,Counter


# 1、namedtuple
Point = namedtuple('Point', ['x', 'y'])
p = Point(1, 2)
print(p.x,p.y)


# 2、deque
q = deque(['a', 'b', 'c'])
q.append('x')
q.appendleft('y')
print(q)

# 3、defaultdict

dd = defaultdict(lambda: 'N/A')
dd['key1'] = 'abc'
print(dd['key1']) # key1存在
print(dd['key2']) # key1存在


# 4、OrderDict
d = dict([("a",1),("c",2),("b",3)])
print(d)
od = OrderedDict([("a",1),("c",2),("b",3)])
print(od)
print(list(od.keys()))

# 5、Counter
c= Counter()
for ch in "programming":
    c[ch] = c[ch] + 1

print(c)


